(() => {

    'use strict';
    goog.provide('Blockly.Arduino.ruilong');
    goog.require('Blockly.Arduino');

     //语音模块（68段日常用语）
    Blockly.Arduino.forBlock['ruilong_pins_voice'] = function () {
        var code = this.getFieldValue('VOICE');
        return [code, Blockly.Arduino.ORDER_ATOMIC];
    };

    Blockly.Arduino.forBlock['ruilong_voice'] = function () {
        var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN', Blockly.Arduino.ORDER_ATOMIC);
        var dropdown_voice = Blockly.Arduino.valueToCode(this, 'VOICE', Blockly.Arduino.ORDER_ATOMIC);
        var wait_time = Blockly.Arduino.valueToCode(this, 'WAIT', Blockly.Arduino.ORDER_ASSIGNMENT) || '0';
        Blockly.Arduino.definitions_['define_RL_Voice68_h'] = '#include<RL_Voice68.h>\n';
        Blockly.Arduino.definitions_['define_Voice68'] = 'VOICE_68 voice_' + dropdown_pin + '(' + dropdown_pin + ');';
        Blockly.Arduino.setups_['setup_Voice68' + dropdown_pin] = 'voice_' + dropdown_pin + '.begin();';
        var code = 'voice_' + dropdown_pin + '.send_data(' + dropdown_voice + '); //volume control 0xE0-E7;\n';
        code += 'delay(' + wait_time + ');\n'

        return code;
    };

    Blockly.Arduino.forBlock['ruilong_voice_NUM'] = function () {
        var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN', Blockly.Arduino.ORDER_ATOMIC);
        var num = Blockly.Arduino.valueToCode(this, 'NUM', Blockly.Arduino.ORDER_ATOMIC);
        var wait_time = Blockly.Arduino.valueToCode(this, 'WAIT', Blockly.Arduino.ORDER_ASSIGNMENT) || '0';
        Blockly.Arduino.definitions_['define_RL_Voice68_h'] = '#include<RL_Voice68.h>\n';
        Blockly.Arduino.definitions_['define_Voice68'] = 'VOICE_68 voice_' + dropdown_pin + '(' + dropdown_pin + ');';
        Blockly.Arduino.setups_['setup_Voice68' + dropdown_pin] = 'voice_' + dropdown_pin + '.begin();';
        var code = 'voice_' + dropdown_pin + '.broadcast_float(' + num + '); \n';
        code += 'delay(' + wait_time + ');\n'

        return code;
    };
    //GD5800 串口MP3模块 控制播放
    Blockly.Arduino.forBlock['ruilong_GD5800_UART_MP3_CONTROL'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var CONTROL_TYPE = this.getFieldValue('CONTROL_TYPE');
        Blockly.Arduino.definitions_['defineGD5800'] = '#include <GD5800_Serial.h>';
        Blockly.Arduino.definitions_['defineGD5800_ mp3' + rxpin + txpin] = 'GD5800_Serial mp3_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';
        Blockly.Arduino.setups_['setup_ mp3' + rxpin + txpin] = ' mp3_' + rxpin + txpin + '.begin(9600);';
        var code = 'mp3_' + rxpin + txpin + '.' + CONTROL_TYPE + '\n';
        code += 'delay(100);\n';
        return code;
    };

    //GD5800 串口MP3模块 循环模式
    Blockly.Arduino.forBlock['ruilong_GD5800_MP3_LOOP_MODE'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var LOOP_MODE = this.getFieldValue('LOOP_MODE');
        Blockly.Arduino.definitions_['include_GD5800'] = '#include <GD5800_Serial.h>';
        Blockly.Arduino.definitions_['var_declare_GD5800_ mp3' + rxpin + txpin] = 'GD5800_Serial mp3' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';
        Blockly.Arduino.setups_['setup_ mp3' + rxpin + txpin] = ' mp3' + rxpin + txpin + '.begin(9600);';
        var code = 'mp3' + rxpin + txpin + '.setLoopMode(' + LOOP_MODE + ');\n';
        return code;
    };

    //GD5800 串口MP3模块 EQ模式
    Blockly.Arduino.forBlock['ruilong_GD5800_MP3_EQ_MODE'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var EQ_MODE = this.getFieldValue('EQ_MODE');
        Blockly.Arduino.definitions_['include_GD5800'] = '#include <GD5800_Serial.h>';
        Blockly.Arduino.definitions_['var_declare_GD5800_ mp3' + rxpin + txpin] = 'GD5800_Serial mp3' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';
        Blockly.Arduino.setups_['setup_ mp3' + rxpin + txpin] = ' mp3' + rxpin + txpin + '.begin(9600);';
        var code = 'mp3' + rxpin + txpin + '.setEqualizer(' + EQ_MODE + ');\n';
        return code;
    };

    //GD5800 串口MP3模块 设置音量
    Blockly.Arduino.forBlock['ruilong_GD5800_MP3_VOL'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var vol = Blockly.Arduino.valueToCode(this, 'vol', Blockly.Arduino.ORDER_ATOMIC);
        Blockly.Arduino.definitions_['include_GD5800'] = '#include <GD5800_Serial.h>';
        Blockly.Arduino.definitions_['var_declare_GD5800_ mp3' + rxpin + txpin] = 'GD5800_Serial mp3' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';
        Blockly.Arduino.setups_['setup_ mp3' + rxpin + txpin] = ' mp3' + rxpin + txpin + '.begin(9600);';
        var code = 'mp3' + rxpin + txpin + '.setVolume(' + vol + ');\n';
        return code;
    };

    //GD5800 串口MP3模块 播放第N首
    Blockly.Arduino.forBlock['ruilong_GD5800_MP3_PLAY_NUM'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var NUM = Blockly.Arduino.valueToCode(this, 'NUM', Blockly.Arduino.ORDER_ATOMIC);
        Blockly.Arduino.definitions_['include_GD5800'] = '#include <GD5800_Serial.h>';
        Blockly.Arduino.definitions_['var_declare_GD5800_ mp3' + rxpin + txpin] = 'GD5800_Serial mp3' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';
        Blockly.Arduino.setups_['setup_ mp3' + rxpin + txpin] = 'mp3' + rxpin + txpin + '.begin(9600);';
        var code = 'mp3' + rxpin + txpin + '.playFileByIndexNumber(' + NUM + ');\n';
        return code;
    };
    //YX5300 串口MP3模块 控制播放
    Blockly.Arduino.forBlock['ruilong_YX5300_UART_MP3_CONTROL'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var CONTROL_TYPE = this.getFieldValue('CONTROL_TYPE');
       // Blockly.Arduino.definitions_['include_YX5300'] = '#include <RL_YX5300_Serial.h>';
        //Blockly.Arduino.definitions_['var_declare_GD5800_ mp3' + rxpin + txpin] = 'YX5300_Serial mp3_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';

        Blockly.Arduino.definitions_['include_YX5300'] = '#include <RL_YX5300_Serial.h>\n';
        Blockly.Arduino.definitions_['var_declare_ mp3' + rxpin + txpin] = 'YX5300_Serial mp3_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_ mp3' + rxpin + txpin] = 'mp3_' + rxpin + txpin + '.begin(9600);';
        var code = 'mp3_' + rxpin + txpin + '.' + CONTROL_TYPE + '\n';
        code += 'delay(100);\n';
        return code;
    };
    //YX5300 串口MP3模块 设置音量
    Blockly.Arduino.forBlock['ruilong_YX5300_MP3_VOL'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var vol = Blockly.Arduino.valueToCode(this, 'vol', Blockly.Arduino.ORDER_ATOMIC);
        Blockly.Arduino.definitions_['include_YX5300'] = '#include <RL_YX5300_Serial.h>\n';
        Blockly.Arduino.definitions_['var_declare_ mp3' + rxpin + txpin] = 'YX5300_Serial mp3_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_ mp3' + rxpin + txpin] = 'mp3_' + rxpin + txpin + '.begin(9600);';
        var code = 'mp3_' + rxpin + txpin + '.setVol(' + vol + ');\n';
        return code;
    };

    //YX5300 串口MP3模块 播放第N首
    Blockly.Arduino.forBlock['ruilong_YX5300_MP3_PLAY_NUM'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var NUM = Blockly.Arduino.valueToCode(this, 'NUM', Blockly.Arduino.ORDER_ATOMIC);
        Blockly.Arduino.definitions_['include_YX5300'] = '#include <RL_YX5300_Serial.h>\n';
        Blockly.Arduino.definitions_['var_declare_ mp3' + rxpin + txpin] = 'YX5300_Serial mp3_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_ mp3' + rxpin + txpin] = 'mp3_' + rxpin + txpin + '.begin(9600);';
        var code = 'mp3_' + rxpin + txpin + '.play(' + NUM + ');\n';
        return code;
    };

    //YX5300 串口MP3模块 循环播放第N首
    Blockly.Arduino.forBlock['ruilong_YX5300_MP3_PLAYSL'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var NUM = Blockly.Arduino.valueToCode(this, 'NUM', Blockly.Arduino.ORDER_ATOMIC);
        Blockly.Arduino.definitions_['include_YX5300'] = '#include <RL_YX5300_Serial.h>\n';
        Blockly.Arduino.definitions_['var_declare_ mp3' + rxpin + txpin] = 'YX5300_Serial mp3_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_ mp3' + rxpin + txpin] = 'mp3_' + rxpin + txpin + '.begin(9600);';
        var code = 'mp3_' + rxpin + txpin + '.playSL(' + NUM + ');\n';
        return code;
    };
    //YX5300 串口MP3模块 循环播放文件夹
    Blockly.Arduino.forBlock['ruilong_YX5300_MP3_PLAYF'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var FOLDER = Blockly.Arduino.valueToCode(this, 'FOLDER', Blockly.Arduino.ORDER_ATOMIC);
        Blockly.Arduino.definitions_['include_YX5300'] = '#include <RL_YX5300_Serial.h>\n';
        Blockly.Arduino.definitions_['var_declare_ mp3' + rxpin + txpin] = 'YX5300_Serial mp3_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_ mp3' + rxpin + txpin] = 'mp3_' + rxpin + txpin + '.begin(9600);';
        var code = 'mp3_' + rxpin + txpin + '.playF(' + FOLDER + ');\n';
        return code;
    };
    //YX5300 串口MP3模块 循环播放在F文件夹 第N首
    Blockly.Arduino.forBlock['ruilong_YX5300_MP3_PLAYFSL'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var FOLDER = Blockly.Arduino.valueToCode(this, 'FOLDER', Blockly.Arduino.ORDER_ATOMIC);
        var NUM = Blockly.Arduino.valueToCode(this, 'NUM', Blockly.Arduino.ORDER_ATOMIC);
        Blockly.Arduino.definitions_['include_YX5300'] = '#include <RL_YX5300_Serial.h>\n';
        Blockly.Arduino.definitions_['var_declare_ mp3' + rxpin + txpin] = 'YX5300_Serial mp3_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_ mp3' + rxpin + txpin] = 'mp3_' + rxpin + txpin + '.begin(9600);';
        var code = 'mp3_' + rxpin + txpin + '.playSL(' + FOLDER + ',' + NUM + ');\n';
        return code;
    };


    //M9101X mp3 单线控制播放
    Blockly.Arduino.forBlock['ruilong_M9101X_S_MP3_CONTROL'] = function () {
        var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN', Blockly.Arduino.ORDER_ATOMIC);
        var CONTROL_TYPE = this.getFieldValue('CONTROL_TYPE');
        Blockly.Arduino.definitions_['defineN910X'] = '#include <RL_N910X.h>';
        Blockly.Arduino.definitions_['defineN910X_ mp3' + dropdown_pin] = 'N910X mp3_' + dropdown_pin + '(' + dropdown_pin + ');';
        Blockly.Arduino.setups_['setup_ mp3' + dropdown_pin] = 'mp3_' + dropdown_pin + '.begin();';
        var code = 'mp3_' + dropdown_pin + '.' + CONTROL_TYPE + '\n';

        return code;
    };

    //M9101X mp3 单线音量控制
    Blockly.Arduino.forBlock['ruilong_M9101X_S_MP3_VOL_CONTROL'] = function () {
        var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN', Blockly.Arduino.ORDER_ATOMIC);
        var vol = Blockly.Arduino.valueToCode(this, 'NUM', Blockly.Arduino.ORDER_ATOMIC);
        Blockly.Arduino.definitions_['defineN910X'] = '#include <RL_N910X.h>';
        Blockly.Arduino.definitions_['defineN910X_ mp3' + dropdown_pin] = 'N910X mp3_' + dropdown_pin + '(' + dropdown_pin + ');';
        Blockly.Arduino.setups_['setup_ mp3' + dropdown_pin] = ' mp3_' + dropdown_pin + '.begin();';
        var code = 'mp3_' + dropdown_pin + '.set_volume(' + vol + ');\n';

        return code;
    };
    //M9101X mp3 单线播放第N首
    Blockly.Arduino.forBlock['ruilong_M9101X_S_MP3_PLAY_NUM'] = function () {
        var dropdown_pin = Blockly.Arduino.valueToCode(this, 'PIN', Blockly.Arduino.ORDER_ATOMIC);
        var num = Blockly.Arduino.valueToCode(this, 'NUM', Blockly.Arduino.ORDER_ATOMIC);
        Blockly.Arduino.definitions_['defineN910X'] = '#include <RL_N910X.h>';
        Blockly.Arduino.definitions_['defineN910X_ mp3' + dropdown_pin] = 'N910X mp3_' + dropdown_pin + '(' + dropdown_pin + ');';
        Blockly.Arduino.setups_['setup_ mp3' + dropdown_pin] = ' mp3_' + dropdown_pin + '.begin();';
        var code = 'mp3_' + dropdown_pin + '.set_play_number(' + num + ');\n';

        return code;
    };
    //SYN6288 机器人语音模块
    Blockly.Arduino.forBlock['ruilong_SYN6288_VOICE_TEXT'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var num = Blockly.Arduino.valueToCode(this, 'NUM', Blockly.Arduino.ORDER_ATOMIC);
        var VOICE_TXT = Blockly.Arduino.valueToCode(this, 'TEXT', Blockly.Arduino.ORDER_ASSIGNMENT);

        Blockly.Arduino.definitions_['defineSYN6288'] = '#include<RL_SYN6288.h>';
        if (!Blockly.Arduino.definitions_['defineSYN6288_ Voice' + rxpin + txpin]) {
            Blockly.Arduino.definitions_['defineSYN6288_ Voice' + rxpin + txpin] = 'SYN6288_Serial Voice_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';
            Blockly.Arduino.setups_['setup_ Voice' + rxpin + txpin] = 'Voice_' + rxpin + txpin + '.begin(9600);';
        }

        Blockly.Arduino.definitions_['size_t_ Voice' + rxpin + txpin + num] = 'size_t unicode_number_' + num + ' = 0;'
        Blockly.Arduino.definitions_['char*_ Voice' + rxpin + txpin + num] = 'char* item_' + num + ' = ' + VOICE_TXT + ';'

        var code = 'Voice_' + rxpin + txpin + '.Output((uint8_t*)utf82unicode(item_' + num + ',&unicode_number_' + num + '),length_of_unicode(item_' + num + '));\n';

        return code;
    };

    Blockly.Arduino.forBlock['ruilong_SYN6288_VOICE_NUM'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var num = Blockly.Arduino.valueToCode(this, 'NUM', Blockly.Arduino.ORDER_ATOMIC);
        var value = Blockly.Arduino.valueToCode(this, 'VALUE', Blockly.Arduino.ORDER_ATOMIC);

        Blockly.Arduino.definitions_['defineSYN6288'] = '#include<RL_SYN6288.h>';
        if (!Blockly.Arduino.definitions_['defineSYN6288_ Voice' + rxpin + txpin]) {
            Blockly.Arduino.definitions_['defineSYN6288_ Voice' + rxpin + txpin] = 'SYN6288_Serial Voice_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';
            Blockly.Arduino.setups_['setup_ Voice' + rxpin + txpin] = 'Voice_' + rxpin + txpin + '.begin(9600);';
        }

        Blockly.Arduino.definitions_['size_t_ Voice' + rxpin + txpin + num] = 'size_t unicode_number_' + num + ' = 0;'
        Blockly.Arduino.definitions_['char*_ Voice' + rxpin + txpin + num] = 'char* item_' + num + ' = "0";'

        var code = 'sprintf(item_' + num + ', "%d", ' + value + ');\n'
            + 'Voice_' + rxpin + txpin + '.Output((uint8_t*)utf82unicode(item_' + num + ',&unicode_number_' + num + '),length_of_unicode(item_' + num + '));\n';

        return code;
    };
    Blockly.Arduino.forBlock['ruilong_SYN6288_VOICE_VOL'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var vol = this.getFieldValue('CONTROL_TYPE');

        Blockly.Arduino.definitions_['defineSYN6288'] = '#include<RL_SYN6288.h>';
        if (!Blockly.Arduino.definitions_['defineSYN6288_ Voice' + rxpin + txpin]) {
            Blockly.Arduino.definitions_['defineSYN6288_ Voice' + rxpin + txpin] = 'SYN6288_Serial Voice_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';
            Blockly.Arduino.setups_['setup_ Voice' + rxpin + txpin] = 'Voice_' + rxpin + txpin + '.begin(9600);';
        }

        Blockly.Arduino.definitions_['size_t_ Voice_vol' + rxpin + txpin] = 'size_t unicode_number_vol = 0;';
        Blockly.Arduino.definitions_['char*_ Voice_vol' + rxpin + txpin] = 'char* item_vol = "' + vol + '";';

        var code = 'Voice_' + rxpin + txpin + '.Output((uint8_t*)utf82unicode(item_vol,&unicode_number_vol),length_of_unicode(item_vol));\n';

        return code;
    };

    Blockly.Arduino.forBlock['ruilong_SYN6288_VOICE_BKVOL'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var bkvol = this.getFieldValue('CONTROL_TYPE');

        Blockly.Arduino.definitions_['defineSYN6288'] = '#include<RL_SYN6288.h>';
        if (!Blockly.Arduino.definitions_['defineSYN6288_ Voice' + rxpin + txpin]) {
            Blockly.Arduino.definitions_['defineSYN6288_ Voice' + rxpin + txpin] = 'SYN6288_Serial Voice_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';
            Blockly.Arduino.setups_['setup_ Voice' + rxpin + txpin] = 'Voice_' + rxpin + txpin + '.begin(9600);';
        }

        Blockly.Arduino.definitions_['size_t_ Voice_kbvol' + rxpin + txpin] = 'size_t unicode_number_kbvol = 0;';
        Blockly.Arduino.definitions_['char*_ Voice_kbvol' + rxpin + txpin] = 'char* item_kbvol = "' + bkvol + '";';

        var code = 'Voice_' + rxpin + txpin + '.Output((uint8_t*)utf82unicode(item_kbvol,&unicode_number_kbvol),length_of_unicode(item_kbvol));\n';

        return code;
    };

    Blockly.Arduino.forBlock['ruilong_SYN6288_VOICE_SPEED'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var speed = this.getFieldValue('CONTROL_TYPE');

        Blockly.Arduino.definitions_['defineSYN6288'] = '#include<RL_SYN6288.h>';
        if (!Blockly.Arduino.definitions_['defineSYN6288_ Voice' + rxpin + txpin]) {
            Blockly.Arduino.definitions_['defineSYN6288_ Voice' + rxpin + txpin] = 'SYN6288_Serial Voice_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';
            Blockly.Arduino.setups_['setup_ Voice' + rxpin + txpin] = 'Voice_' + rxpin + txpin + '.begin(9600);';
        }

        Blockly.Arduino.definitions_['size_t_ Voice_speed' + rxpin + txpin] = 'size_t unicode_number_speed = 0;';
        Blockly.Arduino.definitions_['char*_ Voice_speed' + rxpin + txpin] = 'char* item_speed = "' + speed + '";';

        var code = 'Voice_' + rxpin + txpin + '.Output((uint8_t*)utf82unicode(item_speed,&unicode_number_speed),length_of_unicode(item_speed));\n';

        return code;
    };

    Blockly.Arduino.forBlock['ruilong_SYN6288_VOICE_CONTROL'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var CONTROL_TYPE = this.getFieldValue('CONTROL_TYPE');

        Blockly.Arduino.definitions_['defineSYN6288'] = '#include<RL_SYN6288.h>';
        if (!Blockly.Arduino.definitions_['defineGD5800_ Voice' + rxpin + txpin]) {
            Blockly.Arduino.definitions_['defineGD5800_ Voice' + rxpin + txpin] = 'SYN6288_Serial Voice_' + rxpin + txpin + '(' + rxpin + ', ' + txpin + ');';
            Blockly.Arduino.setups_['setup_ Voice' + rxpin + txpin] = ' Voice_' + rxpin + txpin + '.begin(9600);';
        }
        var code = 'Voice_' + rxpin + txpin + '.' + CONTROL_TYPE + '\n';
        code += 'delay(100);\n';
        return code;
    };

     //DFCK_SNR9816TTS 语音合成模块初始化
    Blockly.Arduino.forBlock['ruilong_SNR9816TTS_SET'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var vol=this.getFieldValue('VOL');
        var speed=this.getFieldValue('SPEED');
        var tone=this.getFieldValue('TONE');
        
        Blockly.Arduino.definitions_['include_RL_SNR9816TTS'] = '#include "RL_SNR9816TTS.h"\n';
        Blockly.Arduino.definitions_['TTS_tts'] = 'TTS tts(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_tts_begin'] = 'tts.begin(115200); ';

        var code = 'tts.setTTSParameters(\'v\','+vol+');\n'
                 + 'tts.setTTSParameters(\'s\','+speed+');\n'
                 + 'tts.setTTSParameters(\'t\','+tone+');\n';

        return code;
    };

    Blockly.Arduino.forBlock['ruilong_SNR9816TTS_TEXT'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        
        Blockly.Arduino.definitions_['include_RL_SNR9816TTS'] = '#include "RL_SNR9816TTS.h"\n';
        Blockly.Arduino.definitions_['TTS_tts'] = 'TTS tts(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_tts_begin'] = 'tts.begin(115200); ';

        var text = Blockly.Arduino.valueToCode(this, 'TEXT', Blockly.Arduino.ORDER_ASSIGNMENT);
        var code = 'tts.speak('+ text +');\n';
        return code;
    };

    Blockly.Arduino.forBlock['ruilong_SNR9816TTS_CONTROL'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        
        Blockly.Arduino.definitions_['include_RL_SNR9816TTS'] = '#include "RL_SNR9816TTS.h"\n';
        Blockly.Arduino.definitions_['TTS_tts'] = 'TTS tts(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_tts_begin'] = 'tts.begin(115200); ';

        var con = this.getFieldValue('CON');

        var code = 'tts.'+con+'();\n';
        return code;
    };

    Blockly.Arduino.forBlock['ruilong_SNR9816TTS_AUDIO'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        
        Blockly.Arduino.definitions_['include_RL_SNR9816TTS'] = '#include "RL_SNR9816TTS.h"\n';
        Blockly.Arduino.definitions_['TTS_tts'] = 'TTS tts(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_tts_begin'] = 'tts.begin(115200); ';

        var text = this.getFieldValue('AUDIO');

        var code = 'tts.speak(\"'+ text +'\");\n';
        return code;
    };

    Blockly.Arduino.forBlock['ruilong_vs1053_midi_GM1'] = function () {

        var GM1 = this.getFieldValue("VS1053_GM1");

        return [GM1, Blockly.Arduino.ORDER_ATOMIC];
    }

    Blockly.Arduino.forBlock['ruilong_vs1053_midi_Instrument'] = function () {

        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var ch = this.getFieldValue('CH');
        var type = this.getFieldValue('TYPE');
        var instrument = Blockly.Arduino.valueToCode(this, 'INSTRUMENT', Blockly.Arduino.ORDER_ATOMIC);
        var volume = Blockly.Arduino.valueToCode(this, 'MIDIVolume', Blockly.Arduino.ORDER_ATOMIC);

        Blockly.Arduino.definitions_['defineRL_VS1053_MIDI'] = '#include <RL_VS1053_MIDI.h>';
        if (!Blockly.Arduino.definitions_['defineRL_VS1053_MIDI' + txpin]) {
            Blockly.Arduino.definitions_['defineRL_VS1053_MIDI  midi_' + txpin] = 'RL_VS1053_MIDI  midi_' + txpin + '(-1, ' + txpin + ');';
            Blockly.Arduino.setups_['setup_  midi_' + txpin] = ' midi_' + txpin + '.begin(31250);';
            Blockly.Arduino.setups_['setup_  midi_Control_Change' + txpin] = ' midi_' + txpin + '.Control_Change(' + ch + ', 0x07, ' + volume + ');';
        }

        var code = 'midi_' + txpin + '.Control_Change(' + ch + ',0,' + type + ');\n '
            + 'midi_' + txpin + '.Program_Change(' + ch + ',' + instrument + ');\n';

        return code;
    };

    Blockly.Arduino.forBlock['ruilong_vs1053_midi_GM1_GM2'] = function () {

        var GM1_GM2 = this.getFieldValue("VS1053_GM1_GM2");

        return [GM1_GM2, Blockly.Arduino.ORDER_ATOMIC];
    }

    Blockly.Arduino.forBlock['ruilong_midiPitch'] = function () {

        var highlist = this.getFieldValue("highlist");
        var midipitch = this.getFieldValue("midipitch");
        var code = parseInt(highlist) + parseInt(midipitch)
        //code = highlist+midipitch;
        return [code, Blockly.Arduino.ORDER_ATOMIC];
    };

    //03T 语音识别模块初始化
    Blockly.Arduino.forBlock['ruilong_03T_GET'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var val = this.getFieldValue('VAL');
        
        Blockly.Arduino.definitions_['include_RL_ASR_03T'] = '#include "RL_ASR_03T.h"\n';
        Blockly.Arduino.definitions_['ASR_03T_asr'] = 'ASR_03T asr(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_asr_begin'] = 'asr.begin(9600);';
        var code = 'asr.ASR_03T_GET('+ val +')';
        return [code, Blockly.Arduino.ORDER_ATOMIC];
    };
    Blockly.Arduino.forBlock['ruilong_03T_NUM'] = function () {
        var rxpin = Blockly.Arduino.valueToCode(this, 'RXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);

        Blockly.Arduino.definitions_['include_RL_ASR_03T'] = '#include "RL_ASR_03T.h"\n';
        Blockly.Arduino.definitions_['ASR_03T_asr'] = 'ASR_03T asr(' + rxpin + ', ' + txpin + ');\n';
        Blockly.Arduino.setups_['setup_asr_begin'] = 'asr.begin(9600);';
         var code = 'asr.ASR_03T_NUM()';

        return  [code, Blockly.Arduino.ORDER_ATOMIC];
    };

    Blockly.Arduino.forBlock['ruilong_vs1053_midi_note'] = function () {

        var txpin = Blockly.Arduino.valueToCode(this, 'TXPIN', Blockly.Arduino.ORDER_ATOMIC);
        var ch = this.getFieldValue('CH');
        var note_on_off = this.getFieldValue('NOTE_ON_OFF');
        var note = Blockly.Arduino.valueToCode(this, 'NOTE', Blockly.Arduino.ORDER_ATOMIC);
        var velocity = Blockly.Arduino.valueToCode(this, 'VELOCITY', Blockly.Arduino.ORDER_ATOMIC);

        Blockly.Arduino.definitions_['defineRL_VS1053_MIDI'] = '#include <RL_VS1053_MIDI.h>';
        if (!Blockly.Arduino.definitions_['defineRL_VS1053_MIDI' + txpin]) {
            Blockly.Arduino.definitions_['defineRL_VS1053_MIDI  midi_' + txpin] = 'RL_VS1053_MIDI  midi_' + txpin + '(-1, ' + txpin + ');';
            Blockly.Arduino.setups_['setup_  midi_' + txpin] = ' midi_' + txpin + '.begin(31250);';
            Blockly.Arduino.setups_['setup_  midi_Control_Change' + txpin] = ' midi_' + txpin + '.Control_Change(' + ch + ', 0x07, 127);';
        }


        if (note_on_off == "1") {
            var code = 'midi_' + txpin + '.noteOn(' + ch + ',' + note + ',' + velocity + ');\n ';
        } else {
            var code = 'midi_' + txpin + '.noteOff(' + ch + ',' + note + ',' + velocity + ');\n ';
        }

        return code;
    };

})();